﻿using BLL;
using gfLibrary;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IYAKASAPortal.Standard
{
    public partial class TYPE_FDJ_CONTENT_List : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            gfAjaxJs.SetNoCache();

            if (Page.IsPostBack == false)
            {
                btnSearch_Click(sender, e);
            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string strKeywords = txtKeywords.Text;

            string strSql = "select * from TYPE_FDJ_CONTENT";

            if (strKeywords.Length > 0)
            {
                strSql += " where ";
                strSql += "ID like '%" + strKeywords + "%'";
                strSql += " or FDJXH like '%" + strKeywords + "%'";
                strSql += " or FDJZZC like '%" + strKeywords + "%'";
                strSql += " or RLLB like '%" + strKeywords + "%'";
                strSql += " or RYBH like '%" + strKeywords + "%'";
                strSql += " or GYFS like '%" + strKeywords + "%'";
                strSql += " or JQFS like '%" + strKeywords + "%'";
                strSql += " or EDGL like '%" + strKeywords + "%'";
                strSql += " or EDZS like '%" + strKeywords + "%'";
                strSql += " or EDNJZS like '%" + strKeywords + "%'";
                strSql += " or EDNJ like '%" + strKeywords + "%'";
                strSql += " or EDYH like '%" + strKeywords + "%'";
                strSql += " or FDJPL like '%" + strKeywords + "%'";
                strSql += " or FDJGS like '%" + strKeywords + "%'";
                strSql += " or FDJCC like '%" + strKeywords + "%'";
            }

            DataTable m_dtTable = new DataTable();
            GreatPager1.BindDataTablePage(ref m_dtTable, Config.AppConfig.g_strConnectionStringSqlClient, strSql, 20);

            rptList.DataSource = m_dtTable;
            rptList.DataBind();

            m_dtTable.Dispose();
        }

        protected void GreatPager1_PageIndexChanging(object sender, gfPage.PagerEventArgs e)
        {
            GreatPager1.PageIndex = e.NewPageIndex;
            btnSearch_Click(sender, null);
        }

        protected void btnSearchAll_Click(object sender, EventArgs e)
        {
            txtKeywords.Text = "";
            btnSearch_Click(sender, e);
        }

        protected void btnBrowse_Click(object sender, EventArgs e)
        {
            string strUniqueKey = Request.Form["txtUniqueKey"];

            if ((strUniqueKey == null) || (strUniqueKey.Length == 0) || (gfValidate.Is_Integer(strUniqueKey) == false))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                return;
            }

            Response.Redirect("TYPE_FDJ_CONTENT_Insert_Update.aspx?m=b&UniqueKey=" + strUniqueKey);
        }

        protected void btnInsert_Click(object sender, EventArgs e)
        {
            Response.Redirect("TYPE_FDJ_CONTENT_Insert_Update.aspx?m=i");
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            string strUniqueKey = Request.Form["txtUniqueKey"];

            if ((strUniqueKey == null) || (strUniqueKey.Length == 0) || (gfValidate.Is_Integer(strUniqueKey) == false))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                return;
            }

            Response.Redirect("TYPE_FDJ_CONTENT_Insert_Update.aspx?m=u&UniqueKey=" + strUniqueKey);
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {

            string strUniqueKey = Request.Form["txtUniqueKey"];

            if ((strUniqueKey == null) || (strUniqueKey.Length == 0) || (gfValidate.Is_Integer(strUniqueKey) == false))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                return;
            }

            TYPE_FDJ_CONTENT_BLL m_TYPE_FDJ_CONTENT_BLL = new TYPE_FDJ_CONTENT_BLL();

            if (m_TYPE_FDJ_CONTENT_BLL.Exists(Convert.ToInt32(strUniqueKey)) == true)
            {
                if (m_TYPE_FDJ_CONTENT_BLL.Delete(Convert.ToInt32(strUniqueKey)) == true)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "删除成功！");
                    btnSearch_Click(sender, e);
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "删除失败！");
                }
            }
        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {
            string strUniqueKey = Request.Form["txtUniqueKey"];
            Response.Redirect("equip_type_Insert_Update.aspx?m=u&UniqueKey=" + strUniqueKey);
        }
    }
}